var FrauenVsRefugees = {};

var VIEW_WIDTH = 622;
var VIEW_HEIGHT = 193;

var TypeWriter = function(t, e, i) {
    this.value = e,
    this.text = t,
    this.speed = i,
    this.currentChar = 0,
    this.onComplete = new Phaser.Signal,
    this.timer = game.time.events.repeat(i, this.value.length, this.type, this)
}
;
TypeWriter.prototype.type = function() {
    return this.currentChar++,
    this.text.text = this.value.substr(0, this.currentChar),
    this.currentChar >= this.value.length ? void this.onComplete.dispatch() : void 0
}

FrauenVsRefugees.Boot = function(t) {
  this.preload = function() {
      t.load.image("intro", "assets/images/intro.png")
      t.load.atlas("frau", "assets/images/anim/wonderwoman.png", "assets/images/anim/wonderwoman.json")
      t.load.bitmapFont("fixedsys", "assets/fonts/fixedsys_0.png", "assets/fonts/fixedsys.fnt")
      t.load.image("game-logo", "assets/images/game-logo.png")
  };
  this.create = function() {
    this.introComplete = 0;
    this.viewWindow = createViewWindow(),
    t.add.existing(this.viewWindow)
    this.group = t.add.group();
    this.groupFont = t.add.group();
    this.viewWindow.addChild(this.group);
    this.viewWindow.addChild(this.groupFont)
    this.intro = t.add.sprite(0, 0, "intro");
    var e = VIEW_WIDTH / this.intro.width;

    this.intro.scale.set(e, e);
    this.group.addChild(this.intro);
    this.frau = t.add.sprite(0, 0, "frau"),
    this.frau.anchor.set(.5, 1),
    
    this.frau.introAnimation = this.frau.animations.add("intro", Phaser.Animation.generateFrameNames("slice", 14, 15, ".png", 2), 10, !0),
    this.frau.introAnimation.play();
    this.frau.x = VIEW_WIDTH / 2,
    this.frau.y = this.intro.height - 60,
    this.frau.scale.set(.7, .7),
    this.group.addChild(this.frau);

    this.groupFont.fixedToCamera = !0,
    this.whereLabel = t.add.bitmapText(10, 10, "fixedsys", "", 22),
    this.groupFont.addChild(this.whereLabel);

    var i = new TypeWriter(this.whereLabel,"WHERE: _",50);
    i.onComplete.add(this.whereLabelComplete, this);

    var o = t.add.sprite(0, 0, "game-logo");
    o.scale.set(.4, .4),
    o.anchor.set(.5, .5),
    o.fixedToCamera = !0,
    o.cameraOffset.set(o.width / 2 + 10, o.height / 2 + 10);

  };
  this.update = function() {
    this.group.y > -this.intro.height + VIEW_HEIGHT + 5 ? this.group.y -= 1 : 0 == this.introComplete && (this.introComplete = !0,
                this.showIntroText());
  }

  this.whereLabelComplete = function() {
    this.whereLabel.hasDashAtTheEnd = !1;
    var e = t.time.events.repeat(250, 8, this.whereLabelBlink, this);
    e.timer.onComplete.addOnce(this.whereValueWrite, this)
  }

  this.whereLabelBlink = function() {
    this.whereLabel.text = 1 == this.whereLabel.hasDashAtTheEnd ? "WHERE:" : "WHERE: _",
    this.whereLabel.hasDashAtTheEnd = !this.whereLabel.hasDashAtTheEnd
  };
  this.whereValueWrite = function() {
    this.whereLabel.text = "WHERE:",
    this.whereValue = t.add.bitmapText(this.whereLabel.width + 20, 10, "fixedsys", "", 22),
    this.groupFont.addChild(this.whereValue),
    this.whereValue.tint = 16711680;
    var e = new TypeWriter(this.whereValue,"Köln, Germany ",50);
    e.onComplete.add(this.whereValueComplete, this)
  }
  this.whereValueComplete = function() {
        this.whenLabel = t.add.bitmapText(10, 30, "fixedsys", "", 22),
        this.groupFont.addChild(this.whenLabel);
        var e = new TypeWriter(this.whenLabel,"WHEN: _",50);
        e.onComplete.add(this.whenLabelComplete, this)
    }
    ,
    this.whenLabelComplete = function() {
        this.whenLabel.hasDashAtTheEnd = !1;
        var e = t.time.events.repeat(250, 8, this.whenLabelBlink, this);
        e.timer.onComplete.addOnce(this.whenValueWrite, this)
    }
    ,
    this.whenLabelBlink = function() {
        this.whenLabel.text = 1 == this.whenLabel.hasDashAtTheEnd ? "WHEN:" : "WHEN: _",
        this.whenLabel.hasDashAtTheEnd = !this.whenLabel.hasDashAtTheEnd
    }
    ,
    this.whenValueWrite = function() {
        this.whenLabel.text = "WHEN:",
        this.whenValue = t.add.bitmapText(this.whereLabel.width + 20, 30, "fixedsys", "", 22),
        this.groupFont.addChild(this.whenValue),
        this.whenValue.tint = 16711680;
        new TypeWriter(this.whenValue,"01.01.2016 00:00:00:000 ",50)
    }
    this.showIntroText = function() {
      this.introText = t.add.bitmapText(10, 130, "fixedsys", "", 16),
      this.groupFont.addChild(this.introText),
      new TypeWriter(this.introText,"The Frau Needs Your Help To Get To The Hauptbahnhof..\nUse Arrow Keys To Move, X/C Keys To Fight. \nPress SPACE To Start",25)
    }

};